﻿using System;
using Adp.Common;
using Yqd.Models;
using System.Linq;

namespace Yqd.Core
{
    public class LoggingService
    {
        public static int AddLog(string EmployeeCode)
        {
            var ctx = Fn.GetService<YqdContext>();
            var dt = DateTime.Now;
            var model = ctx.Yqd_Logging.FirstOrDefault(it => it.EmployeeCode == EmployeeCode && it.Instime.Date == dt.Date);
            if (model != null)
            {
                model.Instime = dt;
            }
            else
            {
                ctx.Yqd_Logging.Add(new Yqd_Logging()
                {
                    EmployeeCode = EmployeeCode,
                    Instime = dt
                });
            }
            return ctx.SaveChanges();
        }
    }
}
